package com.xxx.video.mine.activitys;

import android.os.Bundle;

import androidx.recyclerview.widget.GridLayoutManager;

import com.xxx.video.R;
import com.xxx.video.commen.activitys.BaseActivity;
import com.xxx.video.commen.adapters.BaseRecycleViewAdapter;
import com.xxx.video.commen.utils.ListUtils;
import com.xxx.video.commen.utils.StatusBarUtil;
import com.xxx.video.commen.views.recyclerviews.RefreshRecyclerView;
import com.xxx.video.main.activitys.VideoDetailsActivity;
import com.xxx.video.mine.adapters.BrowseRecordsListAdapter;
import com.xxx.video.mine.beans.BrowseListBean;
import com.xxx.video.mine.presenters.BrowseRecordsPresenter;
import com.xxx.video.mine.presenters.IBrowseRecordsView;

import butterknife.BindView;

public class BrowseRecordsActivity extends BaseActivity<BrowseRecordsPresenter> implements
        IBrowseRecordsView, BaseRecycleViewAdapter.OnItemClickListener<BrowseListBean.PageBean.ListBean>, RefreshRecyclerView.OnRecyclerViewRefreshOrLoadMoreListener {

    @BindView(R.id.rcv_browse_records_list)
    RefreshRecyclerView rcvBrowseRecordsList;
    /**
     * page
     */
    private int page = 1;
    private BrowseRecordsListAdapter mBrowseRecordsListAdapter;

    @Override
    protected BrowseRecordsPresenter createPresenter() {
        return new BrowseRecordsPresenter(this, this);
    }

    @Override
    public void initToolbarData() {
        super.initToolbarData();
        showActionBar();
        StatusBarUtil.getInstance().setStatusBarTransparent(this, true);
        setIsShowActionbarLine(true);
        setActionBarTitle(R.string.title_browse_records_activity);
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_browse_records;
    }

    @Override
    public void initData(Bundle extras) {
        getPresenter().getViewList(page);
    }

    @Override
    public void showRootLayoutStatus(int status) {
        showLayoutStatus(status);
    }

    @Override
    public void initData2View(BrowseListBean successOb) {
        showRootLayoutStatus(1);
        rcvBrowseRecordsList.resetState();
        if (mBrowseRecordsListAdapter == null) {
            rcvBrowseRecordsList.setLayoutManager(new GridLayoutManager(this, 2));
            mBrowseRecordsListAdapter = new BrowseRecordsListAdapter(this);
            mBrowseRecordsListAdapter.setOnItemClickListener(this);
            rcvBrowseRecordsList.setAdapter(mBrowseRecordsListAdapter);
            rcvBrowseRecordsList.setOnRecyclerViewRefreshOrLoadMoreListener(this);
        }
        if (page == 1) {
            mBrowseRecordsListAdapter.setData(successOb.page.list);
            if (ListUtils.isEmpty(successOb.page.list)) {
                showRootLayoutStatus(2);
            }
        } else {
            mBrowseRecordsListAdapter.addData(successOb.page.list);
        }

    }

    @Override
    public void onItemClick(BrowseListBean.PageBean.ListBean listBean, int position, int type) {
        startVideoDetailsActivity(listBean.fContentId);
    }

    @Override
    public void startVideoDetailsActivity(String id) {
        Bundle bundle = new Bundle();
        bundle.putString("Id", id);
        intent2Activity(VideoDetailsActivity.class, bundle);
    }

    @Override
    public void onRecyclerviewRefresh() {
        page = 1;
        getPresenter().getViewList(page);
    }

    @Override
    public void onRecyclerviewLoadMore() {
        page++;
        getPresenter().getViewList(page);
    }
}
